
#include "ZionOneSignalLibrary.h"


#if PLATFORM_ANDROID
#include "Android/AndroidApplication.h"
#include "Android/AndroidJNI.h"
#include <android_native_app_glue.h>
#endif // PLATFORM_ANDROID

#if PLATFORM_IOS
#import <AppDelegate.h>
#endif


UZionOneSignalLibrary::UZionOneSignalLibrary(const FObjectInitializer& ObjectInitializer)
	: Super(ObjectInitializer)
{
}

FString UZionOneSignalLibrary::GetOneSignalUserId()
{
#if PLATFORM_ANDROID
	if (JNIEnv* Env = FAndroidApplication::GetJavaEnv())
	{
		static jmethodID Method = FJavaWrapper::FindMethod(Env, FJavaWrapper::GameActivityClassID, "getUserId", "()Ljava/lang/String;", false);
		jstring ss = (jstring)FJavaWrapper::CallObjectMethod(Env, FJavaWrapper::GameActivityThis, Method);

		jboolean isCopy;
		const char *convertedValue = Env->GetStringUTFChars(ss, &isCopy);
		return FString(convertedValue);
	}

	return FString("");
#elif PLATFORM_IOS
	AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
	NSString *s = [appDelegate onesigUserId];
	return FString(s);
#else
	return FString("");
#endif
}
